﻿namespace SYSoft.Model
{

    public class MessageModel
    {
        public MessageModel()
        {

        }
        public MessageModel(string msg)
        {
            this.msg = msg;
        }
        /// <summary>
        /// 状态码
        /// </summary>
        public int status { get; set; } = 200;
        /// <summary>
        /// 操作是否成功
        /// </summary>
        public bool success { get; set; } = false;
        /// <summary>
        /// 返回信息
        /// </summary>
        public string msg { get; set; } = "服务器异常";


 
        public static MessageModel<T> CreateFailedResult<T>(string msg)
        {
            return new MessageModel<T>()
            {
                status = 500,
                msg = msg
            };
        }



        /// <summary>
        /// 创建并返回一个成功的结果对象
        /// </summary>
        /// <returns>成功的结果对象</returns>
        public static MessageModel CreateSuccessResult()
        {
            return new MessageModel()
            {
                success = true,
                status = 200,
                msg = "success",
            };
        }

        /// <summary>
        /// 创建并返回一个成功的结果对象，并带有一个参数对象
        /// </summary>
        /// <typeparam name="T">参数类型</typeparam>
        /// <param name="value">类型的值对象</param>
        /// <returns>成功的结果对象</returns>
        public static MessageModel<T> CreateSuccessResult<T>(T value)
        {
            return new MessageModel<T>()
            {
                success = true,
                status = 200,
                msg = "success",
                data = value
            };
        }

    }


    /// <summary>
    /// 通用返回信息类
    /// </summary>
    public class MessageModel<T>: MessageModel
    {
        /// <summary>
        /// 返回数据集合
        /// </summary>
        public T data { get; set; }



    }
}
